import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/toPromise';

import { PagedQueryResult, BaseService } from 'iisp-ng';
import {ResultSum, ResultDetailAccount, ResultDetailNode, ResultSumPagedQueryParam} from './model';

declare var restRoot: string;

@Injectable()
export class LedgerCheckService extends BaseService {
	private lcUrl = restRoot + '/irmp-ledger-check';

	constructor(http: Http) { super(http); }
	
	searchResultSum(queryParam: ResultSumPagedQueryParam): Promise<PagedQueryResult<ResultSum>> {
	    return this.searchPage(this.lcUrl + "/result/summaries", queryParam);
	}
	getAccountDetails(dataDate: string, accountCode: string, ccyCode: string): Promise<PagedQueryResult<ResultDetailAccount>> {
		let url = `${this.lcUrl}/result/accountdetails?dataDate=${dataDate}&accountCode=${accountCode}&ccyCode=${ccyCode}`;
		return this.doGet(url);
	}
	
	getNodeDetails(dataDate: string, accountCode: string, ccyCode: string, nodeCode: string): Promise<PagedQueryResult<ResultDetailNode>> {
		let url = `${this.lcUrl}/result/nodedetails?dataDate=${dataDate}&accountCode=${accountCode}&ccyCode=${ccyCode}&nodeCode=${nodeCode}`;
		return this.doGet(url);
	}
	
}